<?php

class DialogController extends CController
{
	const PAGE_SIZE=10;

	/**
	 * @var string specifies the default action to be 'list'.
	 */
	public $defaultAction='findDriverForAppointment';

	/**
	 * @var CActiveRecord the currently loaded data model instance.
	 */
	private $_model;

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			array('application.filters.LoginFilter'),
			//array('application.filters.AuthFilter'),
		);
	}
	
	public function actionFindCustomerForBusiness(){//添加、查询其他业务记录     弹出其他业务客户 
		if(isset($_POST['rt'])) $_GET['rt']=$_POST['rt'];
		$model=Customer_name::model();
		$params=array('id','name');
		$view='customer_business';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	//确认单
	public function actionFindPathForConfirm(){//添加确认单   弹出线路
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Path::model();
		$params=array('loading_place','pod_place','mileage','perform_pay');
		$view='confirm/path_confirm';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindGoodsNameForConfirm(){//添加确认单   弹出货物名称
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		if(isset($_POST['consignor_id'])) $_GET['consignor_id']=$_POST['consignor_id'];
		$model=Goods_name::model();
		$params=array('name');
		$view='confirm/goods_name_confirm';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignor_id='.$_GET['consignor_id']);
		$criteria->order='n_index DESC';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindConsigneeLinkmanForConfirm(){//添加确认单   弹出客户卸货地
		if(isset($_POST['consignee_id'])) $_GET['consignee_id']=$_POST['consignee_id'];
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignee_linkman_info::model();
		$params=array('addr','name','mobile_no');
		$view='confirm/consignee_linkman_confirm';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignee_id='.$_GET['consignee_id']);
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindConsigneeForConfirm(){//添加确认单   弹出客户(收货人)、卸货地
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignee_info::model();
		$params=array('consignee_info.id as id','consignee_info.name as name','cli.addr','cli.name as link_name','cli.mobile_no');
		$view='confirm/consignee_confirm';
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN consignee_linkman_info as cli ON cli.fk_consignee_id=consignee_info.id and cli.state=0";
		$criteria->addCondition('consignee_info.state=0');
		$criteria->group='consignee_info.name';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindConsignorLinkmanForConfirm(){//添加确认单   弹出货主装货地
		if(isset($_POST['consignor_id'])) $_GET['consignor_id']=$_POST['consignor_id'];
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignor_linkman_info::model();
		$params=array('addr','name','mobile_no');
		$view='confirm/consignor_linkman_confirm';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignor_id='.$_GET['consignor_id']);
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindConsignorForConfirm(){//添加确认单   弹出货主(发货人)、第一个装货地
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignor_info::model();
		$params=array('consignor_info.id as id','consignor_info.name as name','cli.addr','cli.name as link_name','cli.mobile_no');
		$view='confirm/consignor_confirm';
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN consignor_linkman_info as cli ON cli.fk_consignor_id=consignor_info.id and cli.state=0";
		$criteria->addCondition('consignor_info.state=0');
		$criteria->group='consignor_info.name';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindDriverForConfirm(){//添加确认单   弹出司机
		if(isset($_POST['driver_number'])) $_GET['driver_number']=$_POST['driver_number'];
		$model=Drivers::model();
		$params=array('name','mobile_no');
		$view='confirm/driver_confirm';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindBoardForConfirm(){//添加确认单   弹出尾板
		$model=Trucks::model();
		$params=array('trucks.reg_no','tti.type_name as type','tti.compute_ratio as compute_ratio','trucks.plate_no');
		$view='confirm/truck_board_confirm';
		$criteria=new CDbCriteria();
		$criteria->join="INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		$criteria->addCondition('trucks.kind=1');
		$criteria->addCondition('trucks.state=0');
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindTruckForConfirm(){//添加确认单   弹出车辆
		if(isset($_POST['app_time'])) $_GET['app_time']=$_POST['app_time'];
		$model=Trucks::model();
		$params=array('trucks.id as id','trucks.plate_no as plate_no','drivers.name as major_driver_name',
		'fuel.front_driving as front_fuel','fuel.light_driving as light_fuel','fuel.empty_driving as empty_fuel',
		'fuel.heavy_driving as heavy_fuel','drivers.mobile_no as manufacturer','tti.type_name as type','tti.compute_ratio as compute_ratio',
		'board.plate_no as board_plate_no','board_tti.type_name as board_type','board_tti.compute_ratio as board_compute_ratio');
		$view='confirm/truck_confirm';
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN drivers ON trucks.fk_driver_id=drivers.id
						 LEFT JOIN fuel_consumption as fuel ON fuel.fk_truck_id=trucks.id and fuel.state=0 and '{$_GET['app_time']}' BETWEEN fuel.effect_date and fuel.lapse_date
						 LEFT JOIN trucks as board ON board.fk_truck_id=trucks.id and board.kind=1 and board.state=0
						 LEFT JOIN truck_type_info as board_tti ON board.fk_type_id=board_tti.id
						 INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		$criteria->addCondition('trucks.kind=0');
		$criteria->addCondition('trucks.state=0');
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	//确确单结束
	
	//派车单
	public function actionFindPathForAppointment(){//添加派车单   弹出线路
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Path::model();
		$params=array('id','loading_place','pod_place','mileage');
		$view='appointment/path_appointment';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindGoodsNameForAppointment(){//添加派车单   弹出货物名称
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		if(isset($_POST['consignor_id'])) $_GET['consignor_id']=$_POST['consignor_id'];
		$model=Goods_name::model();
		$params=array('id','name');
		$view='appointment/goods_name_appointment';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignor_id='.$_GET['consignor_id']);
		$criteria->order='n_index DESC';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindConsigneeLinkmanForAppointment(){//添加派车单   弹出客户卸货地
		if(isset($_POST['consignee_id'])) $_GET['consignee_id']=$_POST['consignee_id'];
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignee_linkman_info::model();
		$params=array('addr','name','mobile_no');
		$view='appointment/consignee_linkman_appointment';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignee_id='.$_GET['consignee_id']);
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindConsigneeForAppointment(){//添加派车单   弹出客户(收货人)、第一个客户名称
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignee_info::model();
		$params=array('consignee_info.id as id','consignee_info.name as name','cli.addr','cli.name as link_name','cli.mobile_no');
		$view='appointment/consignee_appointment';
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN consignee_linkman_info as cli ON cli.fk_consignee_id=consignee_info.id and cli.state=0";
		$criteria->addCondition('consignee_info.state=0');
		$criteria->group='consignee_info.name';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindConsignorLinkmanForAppointment(){//添加派车单   弹出货主装货地
		if(isset($_POST['consignor_id'])) $_GET['consignor_id']=$_POST['consignor_id'];
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignor_linkman_info::model();
		$params=array('addr','name','mobile_no');
		$view='appointment/consignor_linkman_appointment';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignor_id='.$_GET['consignor_id']);
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindConsignorForAppointment(){//添加派车单   弹出货主(发货人)、第一个装货地
		if(isset($_POST['n'])) $_GET['n']=$_POST['n'];
		$model=Consignor_info::model();
		$params=array('consignor_info.id as id','consignor_info.name as name','cli.addr','cli.name as link_name','cli.mobile_no');
		$view='appointment/consignor_appointment';
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN consignor_linkman_info as cli ON cli.fk_consignor_id=consignor_info.id and cli.state=0";
		$criteria->addCondition('consignor_info.state=0');
		$criteria->group='consignor_info.name';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindDriverForAppointment(){//添加派车单   弹出司机
		if(isset($_POST['driver_number'])) $_GET['driver_number']=$_POST['driver_number'];
		$model=Drivers::model();
		$params=array('id','name','mobile_no');
		$view='appointment/driver_appointment';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindBoardForAppointment(){//添加派车单   弹出尾板
		$model=Trucks::model();
		$params=array('trucks.id as id','trucks.reg_no','tti.type_name as type','tti.id as fk_type_id','trucks.plate_no');
		$view='appointment/truck_board_appointment';
		$criteria=new CDbCriteria();
		$criteria->join="INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		$criteria->addCondition('trucks.kind=1');
		$criteria->addCondition('trucks.state=0');
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindTruckForAppointment(){//添加派车单   弹出车辆
		$model=Trucks::model();
		$params=array('trucks.id as id','trucks.plate_no as plate_no','tti.type_name as type','tti.id as fk_type_id',
		'trucks.fk_driver_id','drivers.name as major_driver_name','drivers.mobile_no as manufacturer',
		'board.id as board_id','board.plate_no as board_plate_no','board_tti.type_name as board_type','board_tti.id as board_fk_type_id');
		$view='appointment/truck_appointment';
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN drivers ON trucks.fk_driver_id=drivers.id
						 LEFT JOIN trucks as board ON board.fk_truck_id=trucks.id and board.kind=1 and board.state=0
						 LEFT JOIN truck_type_info as board_tti ON board.fk_type_id=board_tti.id 
						 INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		$criteria->addCondition('trucks.kind=0');
		$criteria->addCondition('trucks.state=0');
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	//派车单结束
	public function actionFindGoodsNameForSchedule(){//添加作业计划单   弹出货物名称
		if(isset($_POST['consignor_id'])) $_GET['consignor_id']=$_POST['consignor_id'];
		$model=Goods_name::model();
		$params=array('id','name');
		$view='goods_name_schedule';
		$criteria=new CDbCriteria();
		$criteria->addCondition('fk_consignor_id='.$_GET['consignor_id']);
		$criteria->order='n_index DESC';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindPathForSchedule(){//添加作业计划单   弹出线路信息
		$model=Path::model();
		$params=array('id','loading_place','pod_place','mileage');
		$view='path_schedule';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindDonsignorForSchedule(){//添加作业计划单   弹出货主(发货人)
		$model=Consignor_info::model();
		$params=array('id','name');
		$view='consignor_schedule';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindDriverForMaintenance(){//添加日常维修费用   弹出司机
		$model=Drivers::model();
		$params=array('id','name');
		$view='driver_maintenance';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindTruckForMaintenance(){//添加日常维修费用所属车辆   弹出车辆
		$model=Trucks::model();
		$params=array('id','plate_no','reg_no');
		$view='truck_maintenance';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition('kind=0');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindTruckBoardForMaintenance(){//添加日常维修弹出车辆/尾板
		$model=Trucks::model();
		$params=array('trucks.id','trucks.plate_no','trucks.reg_no','trucks.kind','truck.id as truck_id','truck.plate_no as truck_plate_no','truck.reg_no as truck_reg_no');
		$view='truck_board_maintenance';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->join="LEFT JOIN trucks as truck ON trucks.fk_truck_id=truck.id and truck.state=0";
		if(isset($_POST['kind'])) $_GET['kind']=$_POST['kind'];//确定查找车辆还是尾板
		$criteria->addCondition('trucks.kind='.$_GET['kind']);
		$criteria->addCondition('trucks.state=0');
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindTruckForVehicle(){//添加保险   弹出车辆/尾板
		$model=Trucks::model();
		$params=array('trucks.id as id','trucks.plate_no as plate_no','trucks.property_owner as property_owner','tti.type_name as type');
		$view='truck_vehicle';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition('trucks.state=0');
		$criteria->addCondition("trucks.plate_no!=''");
		$criteria->join="INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		if(isset($_POST['kind'])) $_GET['kind']=$_POST['kind'];//确定查找车辆还是尾板
		$criteria->addCondition('trucks.kind='.$_GET['kind']);
		if(isset($_POST['vehicle'])) $_GET['vehicle']=$_POST['vehicle'];//查找是否已上保险车辆
		if(!isset($_GET['vehicle'])) $_GET['vehicle']=0;
		if($_GET['vehicle']==1) $criteria->addCondition('trucks.id not in (select fk_truck_id from vehicle_insurance where now()<lapsedate and state=0)');
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindTruckForIdentification(){//添加车辆营运证等级鉴定   弹出车辆/尾板
		$model=Trucks::model();
		$params=array('id','plate_no','property_owner');
		$view='truck_identification';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition("plate_no!=''");
		if(isset($_POST['kind'])) $_GET['kind']=$_POST['kind'];//确定查找车辆还是尾板
		$criteria->addCondition('kind='.$_GET['kind']);
		if(isset($_POST['verif'])) $_GET['verif']=$_POST['verif'];//查找是否已年审车辆
		if(!isset($_GET['verif'])) $_GET['verif']=1;
		if($_GET['verif']==1) $criteria->addCondition('id not in (select fk_truck_id from grade_identification where now()<next_grade_identify_date and state=0)');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindTruckForMandatory(){//添加车辆营运证强制保养   弹出车辆/尾板
		$model=Trucks::model();
		$params=array('id','plate_no','property_owner');
		$view='truck_mandatory';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition("plate_no!=''");
		if(isset($_POST['kind'])) $_GET['kind']=$_POST['kind'];//确定查找车辆还是尾板
		$criteria->addCondition('kind='.$_GET['kind']);
		if(isset($_POST['verif'])) $_GET['verif']=$_POST['verif'];//查找是否已年审车辆
		if(!isset($_GET['verif'])) $_GET['verif']=1;
		if($_GET['verif']==1) $criteria->addCondition('id not in (select fk_truck_id from mandatory_maintenance where now()<next_mm_date and state=0)');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindTruckForVerification(){//添加车辆年审   弹出车辆/尾板
		$model=Trucks::model();
		$params=array('id','plate_no','property_owner');
		$view='truck_verification';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition("plate_no!=''");
		if(isset($_POST['kind'])) $_GET['kind']=$_POST['kind'];//确定查找车辆还是尾板
		$criteria->addCondition('kind='.$_GET['kind']);
		if(isset($_POST['verif'])) $_GET['verif']=$_POST['verif'];//查找是否已年审车辆
		if(!isset($_GET['verif'])) $_GET['verif']=1;
		if($_GET['verif']==1) $criteria->addCondition('id not in (select fk_truck_id from annual_verification_info where now()<next_verify_date and state=0)');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindDriverForAccident(){//添加交通事故   弹出司机
		$model=Drivers::model();
		$params=array('id','name');
		$view='driver_accident';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindTruckForAccident(){//添加交通事故   弹出车辆
		$model=Trucks::model();
		$params=array('id','plate_no','property_owner');
		$view='truck_accident';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition('kind=0');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindStaffForCollection(){//添加员工评比弹出司机
		$model=Drivers::model();
		$params=array('id','name');
		$view='staff_collection';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		if(isset($_POST['check'])) $_GET['check']=$_POST['check'];
		if(!isset($_GET['check'])) $_GET['check']=1;
		if(isset($_POST['examine_date'])) $_GET['examine_date']=$_POST['examine_date'];
		if(!isset($_GET['examine_date'])) $_GET['examine_date']='';
		if($_GET['check']==1){
	        $criteria->addCondition('id not in (select fk_driver_id from staff_collection where examine_date="'. $_GET['examine_date'].'-01" and state=0)');
		}
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindTruckForOdometerNo(){//添加公里读数弹出车辆
		$model=Trucks::model();
		$params=array('plate_no');
		$view='truck_odometer_no';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition('kind=0');
		if(isset($_POST['check'])) $_GET['check']=$_POST['check'];
		if(!isset($_GET['check'])) $_GET['check']=1;
		if(isset($_POST['odom_date'])) $_GET['odom_date']=$_POST['odom_date'];
		if(!isset($_GET['odom_date'])) $_GET['odom']='';
		if($_GET['check']==1){
	        $criteria->addCondition('plate_no not in (select plate_no from odometer_no where odom_date="'. $_GET['odom_date'].'-01" and state=0)');
		}
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindTypeForTailBoard(){//添加尾板/车辆   弹出车型
		$model=Truck_type_info::model();
		$params=array('type_name','id');
		$view='type_tail_board';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindTruckForTailBoard(){//添加尾板弹出车辆
		$model=Trucks::model();
		$params=array('plate_no','id');
		$view='truck_tail_board';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition('kind=0');
		if(isset($_POST['truck'])) $_GET['truck']=$_POST['truck'];
		if(!isset($_GET['truck'])) $_GET['truck']=1;
		if($_GET['truck']==1) $criteria->addCondition('id not in (select fk_truck_id from trucks where kind=1 and state=0)');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	public function actionFindTypeForMeritRatio(){//添加绩效工资考核系数/标准油耗   弹出车型
		$model=Truck_type_info::model();
		$params=array('id','type_name');
		$view='type_merit_ratio';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindTruckForFuelConsumption(){//添加标准油耗   弹出车辆
		$model=Trucks::model();
		$params=array('trucks.id as id','trucks.plate_no as plate_no','trucks.fk_type_id as fk_type_id','tti.type_name as type');
		$view='truck_fuel_consumption';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->join="INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		$criteria->addCondition('trucks.kind=0');
		$criteria->addCondition('trucks.state=0');
		//$criteria->addCondition('trucks.id not in (select fk_truck_id from fuel_consumption where state=0)');
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindTruckForMeritRatio(){//添加绩效工资考核系数  弹出车辆
		$model=Trucks::model();
		$params=array('trucks.id as id','trucks.plate_no as plate_no','trucks.fk_type_id as fk_type_id','tti.type_name as type');
		$view='truck_merit_ratio';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->join="INNER JOIN truck_type_info as tti ON trucks.fk_type_id=tti.id";
		$criteria->addCondition('trucks.kind=0');
		$criteria->addCondition('trucks.state=0');
		//$criteria->addCondition('trucks.id not in (select fk_truck_id from merit_pay_ratio where state=0)');
		$this->search($model,$params,$view,$page_size,$criteria,true);
	}
	
	public function actionFindConsignorForGoodsName(){//添加货物名称弹出货主
		$model=Consignor_info::model();
		$params=array('name','id');
		$view='consignor_goods_name';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindDriverFroTruck(){//添加车辆弹出司机
		$model=Drivers::model();
		$params=array('id','name');
		$view='driver_truck';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		if(isset($_POST['truck'])) $_GET['truck']=$_POST['truck'];
		if(!isset($_GET['truck'])) $_GET['truck']=1;
		if($_GET['truck']==1) $criteria->addCondition('id not in (select fk_driver_id from trucks where state=0)');
		$this->search($model,$params,$view,$page_size,$criteria);
	}

	public function actionFindTruckForToRepair(){//添加待修车辆弹出车辆
		$model=Trucks::model();
		$params=array('id','plate_no','reg_no','kind');
		$view='truck_repair';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$this->search($model,$params,$view,$page_size);
	}
	
	public function actionFindTruckForConstantExpense(){//添加固定费用弹出车辆
		$model=Trucks::model();
		$params=array('plate_no','id');
		$view='truck_constant_expense';
		$page_size=Yii::app()->params['dialog'][$this->action->id]['page_size'];
		$criteria=new CDbCriteria();
		$criteria->addCondition('kind=0');
		//if(isset($_POST['ce'])) $_GET['ce']=$_POST['ce'];取消判断是否已添加月固定费用
		//if(!isset($_GET['ce']))	$_GET['ce']=1;
		//if($_GET['ce']==1) $criteria->addCondition('id not in (select fk_truck_id from constant_expense where state=0)');
		$this->search($model,$params,$view,$page_size,$criteria);
	}
	
	private function search($model,$params,$view,$page_size,$criteria=null,$state=null){
		$criteria=$criteria==null?new CDbCriteria():$criteria;
		if($state==null)
			$criteria->addCondition('state=0');
		$criteria->select=$params; 
		$blur=true;
		if(Yii::app()->getRequest()->isPostRequest){
			if(isset($_POST['keys'])){//页面传来的搜索关键字数组
				$_GET['keys']=$_POST['keys'];
			}
		}
		if(isset($_GET['keys'])){
			if(isset($_GET['keys']['blur'])&&$_GET['keys']['blur']=='0') $blur=false;
			foreach($_GET['keys'] as $key=>$val){
				if(trim($val)=='')
					unset($_GET['keys'][$key]);
				else if($key!='blur'){//按照模糊或精确查询
					$blur?$criteria->addSearchCondition($key,$val):$criteria->addCondition("{$key}='{$val}'");
				}
			}
		}
		$pages=new CPagination($model->count($criteria));
		$pages->pageSize=$page_size;
		$pages->applyLimit($criteria);
		$models=$model->findAll($criteria);
		$this->render($view,array(
			'models'=>$models,
			'pages'=>$pages,
		));
	}
}
